<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function breathe(amount){
            return new Promise((resolve,reject)=>{
                if (amount < 500){
                    reject('that is too small of a value');
                }
                setTimeout(()=>resolve(`Done for ${amount} ms`),amount)
            })

        }
        async function go(name,last){
            const res = await breathe(10000);
            console.log(res);
            const res2 = await breathe(300);
            console.log(res2);
            const res3 = await breathe(750);
            console.log(res3);
            const res4 = await breathe(900);
            console.log(res4);
        }
        //高阶函数
        function catchErrors(fn){
            console.log(fn,'***********');
            return function(...args){
                return fn(...args).catch((err)=>{
                    console.error(err);
                })
            }
        }
        const wrappedFunction = catchErrors(go);
        wrappedFunction('Wes','Bos');
    </script>
    
</body>
</html>